<?php

namespace app\user\controller;

use think\Controller;
use think\Request;
use app\common\traits\controller\TraitController;

/**
 * 充值
 */
class Recharge extends Controller
{
    use TraitController;

    public function postDo()
    {
        $user_id = $this->request->post('user_id');
        $amount  = $this->request->post('amount');
        $pt      = $this->request->post('pt', 'wx_pay');

        if ($sign && $user_id && $amount && $pt) {
            //生成未支付充值订单
            $post_order_info = [
                'user_id' => $user_id,
                'amount'  => $amount,
                'pt'      => $pt,
                'status'  => 0
            ];

            $order = model('RechargesOrders')->createOrder($post_order_info);
            
            $params = [
                'type'     => 'recharge', 
                'pt'       => $pt, 
                'order_id' => $order->order_id,
                'user_id'  => self::getLoginUserInfo('id'),
                'amount'   => $amount
            ];

            $sign   = $this->mixSign($params);

            $this->redirect(url('wxpay/payment'), array_merge($params, ['sign' => $sign]);
        }
        return false;
        
    }
    /**
     * 充值视图
     * @return [type] [description]
     */
    public function getRecharge()
    {
        return view('recharge');
    }
    public function getOrder()
    {
        $order_id = $this->request->get('order_id');

        if ($order = model('Orders')->getOrderInfo($order_id)) {
            return view('order', ['data' => $order]);
        }
    }
    public function getOrderList()
    {
        $order_lists = model('Orders')->getOrderLists();
        view('orderlist', ['lists' => $order_lists]);
    }
    public function FunctionName($value='')
    {
        # code...
    }
}
